<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Metodología de la Programación II: Fichero Fuente src/VectorBits.cpp</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generado por Doxygen 1.5.5 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Página&nbsp;principal</span></a></li>
      <li><a href="classes.html"><span>Clases</span></a></li>
      <li class="current"><a href="files.html"><span>Archivos</span></a></li>
    </ul>
  </div>
<h1>src/VectorBits.cpp</h1><a href="VectorBits_8cpp.html">Ir a la documentación de este archivo.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00008"></a>00008 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;<a class="code" href="VectorBits_8h.html" title="Interfaz para trabajar con vectores de bits.">VectorBits.h</a>&gt;</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="keyword">using namespace </span>std;
<a name="l00013"></a>00013 
<a name="l00014"></a><a class="code" href="classVectorBits.html#974d67871a5254c142623b8f683ba165">00014</a> <a class="code" href="classVectorBits.html#974d67871a5254c142623b8f683ba165" title="Constructor por defecto  inicializa todo a cero.">VectorBits :: VectorBits</a>()
<a name="l00015"></a>00015 {
<a name="l00016"></a>00016         v=0;
<a name="l00017"></a>00017         nbits=0;
<a name="l00018"></a>00018         reservados=0;
<a name="l00019"></a>00019 }
<a name="l00020"></a>00020 
<a name="l00021"></a><a class="code" href="classVectorBits.html#72530f5c4181f19e3326a0d2a5213b1d">00021</a> <a class="code" href="classVectorBits.html#974d67871a5254c142623b8f683ba165" title="Constructor por defecto  inicializa todo a cero.">VectorBits :: VectorBits</a> (<span class="keywordtype">int</span> valor, <span class="keywordtype">int</span> n)
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023         nbits=0;
<a name="l00024"></a>00024         reservados=0;
<a name="l00025"></a>00025         v=0;
<a name="l00026"></a>00026         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;n;i++)
<a name="l00027"></a>00027         {
<a name="l00028"></a>00028                 <span class="keywordtype">int</span> resto = valor%2;
<a name="l00029"></a>00029                 *<span class="keyword">this</span> += resto;
<a name="l00030"></a>00030                 valor=valor/2;
<a name="l00031"></a>00031         }
<a name="l00032"></a>00032 }
<a name="l00033"></a>00033 
<a name="l00034"></a><a class="code" href="classVectorBits.html#233b599fe661700280011825faecd726">00034</a> <a class="code" href="classVectorBits.html#974d67871a5254c142623b8f683ba165" title="Constructor por defecto  inicializa todo a cero.">VectorBits :: VectorBits</a>(<span class="keyword">const</span> <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; orig)
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036         nbits=orig.<a class="code" href="classVectorBits.html#8a47fe2c241c0a92b85abeefc05e58ce">nbits</a>;
<a name="l00037"></a>00037         reservados=orig.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>;
<a name="l00038"></a>00038         <span class="keywordflow">if</span> (orig.<a class="code" href="classVectorBits.html#a315fb7bcdefcf3f2e082dd9c47ceb49">v</a> != 0)
<a name="l00039"></a>00039         {
<a name="l00040"></a>00040                 v=<span class="keyword">new</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>[orig.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>];
<a name="l00041"></a>00041                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;orig.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>; i++)
<a name="l00042"></a>00042                         v[i]=orig.<a class="code" href="classVectorBits.html#a315fb7bcdefcf3f2e082dd9c47ceb49">v</a>[i];
<a name="l00043"></a>00043         }
<a name="l00044"></a>00044         <span class="keywordflow">else</span> v=0;
<a name="l00045"></a>00045 }
<a name="l00046"></a>00046 
<a name="l00047"></a><a class="code" href="classVectorBits.html#0ce38d96cbbab31ee4f45da6bd390746">00047</a> <a class="code" href="classVectorBits.html#0ce38d96cbbab31ee4f45da6bd390746" title="Destructor  libera toda la memoria reservada.">VectorBits :: ~VectorBits</a>()
<a name="l00048"></a>00048 {
<a name="l00049"></a>00049         <span class="keywordflow">if</span> (v != 0)
<a name="l00050"></a>00050                 <span class="keyword">delete</span> [] v;
<a name="l00051"></a>00051 }
<a name="l00052"></a>00052 
<a name="l00053"></a><a class="code" href="classVectorBits.html#126d89fd9af6e80384c77bf14c919b96">00053</a> <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; <a class="code" href="classVectorBits.html#126d89fd9af6e80384c77bf14c919b96" title="Operador de asignación.">VectorBits :: operator= </a>(<span class="keyword">const</span> <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; orig)
<a name="l00054"></a>00054 {
<a name="l00055"></a>00055         <span class="keywordflow">if</span> (<span class="keyword">this</span> != &amp;orig)
<a name="l00056"></a>00056         {
<a name="l00057"></a>00057                 <span class="keywordflow">if</span> (v != 0)
<a name="l00058"></a>00058                         <span class="keyword">delete</span> [] v;
<a name="l00059"></a>00059                 <span class="keywordflow">if</span> (orig.<a class="code" href="classVectorBits.html#a315fb7bcdefcf3f2e082dd9c47ceb49">v</a> != 0)
<a name="l00060"></a>00060                 {
<a name="l00061"></a>00061                         v=<span class="keyword">new</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>[orig.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>];
<a name="l00062"></a>00062                         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;orig.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>; i++)
<a name="l00063"></a>00063                                 v[i]=orig.<a class="code" href="classVectorBits.html#a315fb7bcdefcf3f2e082dd9c47ceb49">v</a>[i];         
<a name="l00064"></a>00064                 }
<a name="l00065"></a>00065                 <span class="keywordflow">else</span> v=0;
<a name="l00066"></a>00066                 nbits=orig.<a class="code" href="classVectorBits.html#8a47fe2c241c0a92b85abeefc05e58ce">nbits</a>;
<a name="l00067"></a>00067                 reservados=orig.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>;
<a name="l00068"></a>00068         }
<a name="l00069"></a>00069         <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 
<a name="l00072"></a><a class="code" href="classVectorBits.html#6f1a1382e91395706440cd6321aada60">00072</a> <span class="keywordtype">void</span> <a class="code" href="classVectorBits.html#6f1a1382e91395706440cd6321aada60" title="Modifica un elemento del vector.">VectorBits :: SetVector</a> (<span class="keywordtype">bool</span> dato, <span class="keywordtype">int</span> pos)
<a name="l00073"></a>00073 {
<a name="l00074"></a>00074         assert (pos&gt;=0 &amp;&amp; pos &lt;nbits); 
<a name="l00075"></a>00075         <span class="keywordtype">int</span> pbytes = pos/8;
<a name="l00076"></a>00076         <span class="keywordtype">int</span> pbits = pos%8;
<a name="l00077"></a>00077         <span class="keywordflow">if</span> (dato==1)
<a name="l00078"></a>00078                 v[pbytes]|=(1&lt;&lt;pbits);
<a name="l00079"></a>00079         <span class="keywordflow">else</span> v[pbytes]&amp;= ~(1&lt;&lt;pbits);
<a name="l00080"></a>00080 }
<a name="l00081"></a>00081 
<a name="l00082"></a><a class="code" href="classVectorBits.html#1e24785fe2cdf9252011a2e1dd6b6005">00082</a> <span class="keywordtype">bool</span> <a class="code" href="classVectorBits.html#1e24785fe2cdf9252011a2e1dd6b6005">VectorBits :: GetVector</a> (<span class="keywordtype">int</span> pos)<span class="keyword"> const</span>
<a name="l00083"></a>00083 <span class="keyword"></span>{
<a name="l00084"></a>00084         assert (pos&gt;=0 &amp;&amp; pos &lt;nbits); 
<a name="l00085"></a>00085         <span class="keywordtype">int</span> pbytes = pos/8;
<a name="l00086"></a>00086         <span class="keywordtype">int</span> pbits = pos%8;
<a name="l00087"></a>00087         <span class="keywordflow">return</span> (v[pbytes]&amp;(1&lt;&lt;pbits));
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 
<a name="l00090"></a><a class="code" href="classVectorBits.html#362c5a4cc2fee53d8cfde0d247fb720c">00090</a> <span class="keywordtype">int</span> <a class="code" href="classVectorBits.html#362c5a4cc2fee53d8cfde0d247fb720c">VectorBits :: GetNbits</a> ()<span class="keyword"> const</span>
<a name="l00091"></a>00091 <span class="keyword"></span>{
<a name="l00092"></a>00092         <span class="keywordflow">return</span> nbits;
<a name="l00093"></a>00093 }
<a name="l00094"></a>00094 
<a name="l00095"></a><a class="code" href="classVectorBits.html#8c5c2fa98c37ab750051a3cd0857782c">00095</a> <span class="keywordtype">bool</span> <a class="code" href="classVectorBits.html#8c5c2fa98c37ab750051a3cd0857782c" title="Operador de igualdad.">VectorBits :: operator== </a>(<span class="keyword">const</span> <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; orig)<span class="keyword"> const</span>
<a name="l00096"></a>00096 <span class="keyword"></span>{
<a name="l00097"></a>00097         <span class="keywordflow">if</span> (nbits != orig.<a class="code" href="classVectorBits.html#8a47fe2c241c0a92b85abeefc05e58ce">nbits</a>)
<a name="l00098"></a>00098                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00099"></a>00099         <span class="keywordflow">else</span>
<a name="l00100"></a>00100         {
<a name="l00101"></a>00101                 <span class="keywordtype">int</span> tam=(nbits+7)/8;
<a name="l00102"></a>00102                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;tam; i++)
<a name="l00103"></a>00103                         <span class="keywordflow">if</span> (v[i] != orig.<a class="code" href="classVectorBits.html#a315fb7bcdefcf3f2e082dd9c47ceb49">v</a>[i])
<a name="l00104"></a>00104                                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00105"></a>00105                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00106"></a>00106         }
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108 
<a name="l00109"></a><a class="code" href="classVectorBits.html#f70a5d460f224248465496e59cd5919c">00109</a> <span class="keywordtype">bool</span> <a class="code" href="classVectorBits.html#f70a5d460f224248465496e59cd5919c" title="Operador de desigualdad.">VectorBits :: operator!= </a>(<span class="keyword">const</span> <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; orig)<span class="keyword"> const</span>
<a name="l00110"></a>00110 <span class="keyword"></span>{
<a name="l00111"></a>00111         <span class="keywordflow">if</span> (*<span class="keyword">this</span> == orig) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00112"></a>00112         <span class="keywordflow">else</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114 
<a name="l00115"></a><a class="code" href="classVectorBits.html#0323e93f3b480dae4a54bc4e0e386a3c">00115</a> <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; <a class="code" href="classVectorBits.html#0323e93f3b480dae4a54bc4e0e386a3c" title="Operador +=, añade un tipo bool a la secuencia de bits.">VectorBits :: operator+= </a>(<span class="keywordtype">bool</span> dato)
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117         <span class="keywordtype">int</span> pbytes = nbits/8;
<a name="l00118"></a>00118 
<a name="l00119"></a>00119         <span class="keywordflow">if</span> (pbytes == reservados)
<a name="l00120"></a>00120                 <a class="code" href="classVectorBits.html#2aa7ee65059d5ee23253405039c1d1ce" title="Redimensiona el vector.">Resize</a>(reservados+1);
<a name="l00121"></a>00121         nbits++;
<a name="l00122"></a>00122         <a class="code" href="classVectorBits.html#6f1a1382e91395706440cd6321aada60" title="Modifica un elemento del vector.">SetVector</a>(dato,nbits-1);
<a name="l00123"></a>00123         <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00124"></a>00124 }
<a name="l00125"></a>00125 
<a name="l00126"></a><a class="code" href="classVectorBits.html#e5ce2208c66e5bced89e3752ebc30dcb">00126</a> <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; <a class="code" href="classVectorBits.html#0323e93f3b480dae4a54bc4e0e386a3c" title="Operador +=, añade un tipo bool a la secuencia de bits.">VectorBits :: operator+= </a>(<span class="keyword">const</span> <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; orig)
<a name="l00127"></a>00127 {
<a name="l00128"></a>00128         <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> aux;
<a name="l00129"></a>00129         aux.<a class="code" href="classVectorBits.html#8a47fe2c241c0a92b85abeefc05e58ce">nbits</a>=nbits+orig.<a class="code" href="classVectorBits.html#8a47fe2c241c0a92b85abeefc05e58ce">nbits</a>;
<a name="l00130"></a>00130         aux.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>=(aux.<a class="code" href="classVectorBits.html#8a47fe2c241c0a92b85abeefc05e58ce">nbits</a>+7)/8;
<a name="l00131"></a>00131         aux.<a class="code" href="classVectorBits.html#a315fb7bcdefcf3f2e082dd9c47ceb49">v</a>=<span class="keyword">new</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> [aux.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>];
<a name="l00132"></a>00132         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0;i&lt;aux.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>;++i) 
<a name="l00133"></a>00133       aux.<a class="code" href="classVectorBits.html#a315fb7bcdefcf3f2e082dd9c47ceb49">v</a>[i]=0;
<a name="l00134"></a>00134         memcpy (aux.<a class="code" href="classVectorBits.html#a315fb7bcdefcf3f2e082dd9c47ceb49">v</a>,this-&gt;v,(nbits+7)/8);
<a name="l00135"></a>00135         <span class="keywordtype">int</span> j=0;
<a name="l00136"></a>00136         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=nbits; j&lt; orig.<a class="code" href="classVectorBits.html#8a47fe2c241c0a92b85abeefc05e58ce">nbits</a>; i++,j++)
<a name="l00137"></a>00137         {
<a name="l00138"></a>00138                 aux.<a class="code" href="classVectorBits.html#6f1a1382e91395706440cd6321aada60" title="Modifica un elemento del vector.">SetVector</a>(orig.<a class="code" href="classVectorBits.html#1e24785fe2cdf9252011a2e1dd6b6005">GetVector</a>(j),i);
<a name="l00139"></a>00139         }
<a name="l00140"></a>00140 
<a name="l00141"></a>00141         swap (nbits,aux.<a class="code" href="classVectorBits.html#8a47fe2c241c0a92b85abeefc05e58ce">nbits</a>);
<a name="l00142"></a>00142         swap (reservados,aux.<a class="code" href="classVectorBits.html#3566ec22e94a5748f4f62ca0b77f1c8c">reservados</a>);
<a name="l00143"></a>00143         swap (v, aux.<a class="code" href="classVectorBits.html#a315fb7bcdefcf3f2e082dd9c47ceb49">v</a>);
<a name="l00144"></a>00144         <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00145"></a>00145 }
<a name="l00146"></a>00146 
<a name="l00147"></a><a class="code" href="classVectorBits.html#44092cb51d142b1760174d81fe43551e">00147</a> <span class="keywordtype">int</span> <a class="code" href="classVectorBits.html#44092cb51d142b1760174d81fe43551e">VectorBits :: GetReservados</a> ()<span class="keyword"> const</span>
<a name="l00148"></a>00148 <span class="keyword"></span>{
<a name="l00149"></a>00149         <span class="keywordflow">return</span> reservados;
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
<a name="l00152"></a>00152 ostream &amp; operator&lt;&lt; (ostream&amp; os, <span class="keyword">const</span> <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; vector)
<a name="l00153"></a>00153 {
<a name="l00154"></a>00154         <span class="keywordtype">int</span> usados=vector.<a class="code" href="classVectorBits.html#362c5a4cc2fee53d8cfde0d247fb720c">GetNbits</a>();
<a name="l00155"></a>00155         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt; usados; i++)
<a name="l00156"></a>00156                 os&lt;&lt;vector.<a class="code" href="classVectorBits.html#1e24785fe2cdf9252011a2e1dd6b6005">GetVector</a>(i);
<a name="l00157"></a>00157         <span class="keywordflow">return</span> os;
<a name="l00158"></a>00158 }
<a name="l00159"></a>00159 
<a name="l00160"></a>00160 istream &amp; operator&gt;&gt; (istream&amp; is, <a class="code" href="classVectorBits.html" title="Modulo que representa un vector de bits.">VectorBits</a> &amp; vector)
<a name="l00161"></a>00161 {
<a name="l00162"></a>00162         vector=<a class="code" href="classVectorBits.html#974d67871a5254c142623b8f683ba165" title="Constructor por defecto  inicializa todo a cero.">VectorBits</a>();
<a name="l00163"></a>00163         <span class="keywordtype">char</span> dato;
<a name="l00164"></a>00164         <span class="keywordflow">while</span> (is.peek()==<span class="charliteral">'1'</span> || is.peek()==<span class="charliteral">'0'</span>)
<a name="l00165"></a>00165         {
<a name="l00166"></a>00166                 dato=is.get();
<a name="l00167"></a>00167                 <span class="keywordflow">if</span> (dato == <span class="charliteral">'1'</span>)
<a name="l00168"></a>00168                         vector += 1;
<a name="l00169"></a>00169                 <span class="keywordflow">else</span> vector += 0;
<a name="l00170"></a>00170         }
<a name="l00171"></a>00171         <span class="keywordflow">return</span> is;
<a name="l00172"></a>00172 }
<a name="l00173"></a>00173 
<a name="l00174"></a><a class="code" href="classVectorBits.html#2aa7ee65059d5ee23253405039c1d1ce">00174</a> <span class="keywordtype">void</span> <a class="code" href="classVectorBits.html#2aa7ee65059d5ee23253405039c1d1ce" title="Redimensiona el vector.">VectorBits :: Resize</a> (<span class="keywordtype">int</span> n)
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176         assert (n&gt;=0);
<a name="l00177"></a>00177         <span class="keywordflow">if</span> (n==0)
<a name="l00178"></a>00178         {
<a name="l00179"></a>00179                 <span class="keywordflow">if</span> (v != 0)
<a name="l00180"></a>00180                 {
<a name="l00181"></a>00181                         <span class="keyword">delete</span> [] v;
<a name="l00182"></a>00182                         v =0;
<a name="l00183"></a>00183                 }
<a name="l00184"></a>00184         }
<a name="l00185"></a>00185         <span class="keywordflow">else</span>
<a name="l00186"></a>00186         {
<a name="l00187"></a>00187                 <span class="keywordflow">if</span> (reservados == 0)
<a name="l00188"></a>00188                 {
<a name="l00189"></a>00189                         v=<span class="keyword">new</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>[n];
<a name="l00190"></a>00190                         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;n; i++)
<a name="l00191"></a>00191                                 v[i]=0;
<a name="l00192"></a>00192                 }
<a name="l00193"></a>00193                 <span class="keywordflow">else</span>
<a name="l00194"></a>00194                 {
<a name="l00195"></a>00195                         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *aux=<span class="keyword">new</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>[n];
<a name="l00196"></a>00196                         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;n; i++)
<a name="l00197"></a>00197                                 aux[i]=0;
<a name="l00198"></a>00198                         <span class="keywordflow">if</span> (n &gt;= reservados)
<a name="l00199"></a>00199                                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;reservados;i++)
<a name="l00200"></a>00200                                         aux[i]=v[i];
<a name="l00201"></a>00201                         <span class="keywordflow">else</span> 
<a name="l00202"></a>00202                                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;n;i++)
<a name="l00203"></a>00203                                         aux[i]=v[i];
<a name="l00204"></a>00204                         <span class="keyword">delete</span> [] v;
<a name="l00205"></a>00205                         v = aux;                
<a name="l00206"></a>00206                 }
<a name="l00207"></a>00207         }
<a name="l00208"></a>00208         reservados=n;
<a name="l00209"></a>00209 }
<a name="l00210"></a>00210 
<a name="l00211"></a><a class="code" href="classVectorBits.html#bd4269b1e0b4d622bee00afd7a1a3c36">00211</a> <span class="keywordtype">void</span> <a class="code" href="classVectorBits.html#bd4269b1e0b4d622bee00afd7a1a3c36" title="función que invierte los bits de un vector  el vector queda invertido">VectorBits :: Invertir</a>()
<a name="l00212"></a>00212 {
<a name="l00213"></a>00213         <span class="keywordtype">bool</span> izq,der;
<a name="l00214"></a>00214         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;nbits/2; i++)
<a name="l00215"></a>00215         {
<a name="l00216"></a>00216                 izq = <a class="code" href="classVectorBits.html#1e24785fe2cdf9252011a2e1dd6b6005">GetVector</a>(nbits-1-i);
<a name="l00217"></a>00217                 der = <a class="code" href="classVectorBits.html#1e24785fe2cdf9252011a2e1dd6b6005">GetVector</a>(i);
<a name="l00218"></a>00218                 <a class="code" href="classVectorBits.html#6f1a1382e91395706440cd6321aada60" title="Modifica un elemento del vector.">SetVector</a>(der,nbits-1-i);
<a name="l00219"></a>00219                 <a class="code" href="classVectorBits.html#6f1a1382e91395706440cd6321aada60" title="Modifica un elemento del vector.">SetVector</a>(izq,i);
<a name="l00220"></a>00220         }
<a name="l00221"></a>00221 }
<a name="l00222"></a>00222 
<a name="l00223"></a>00223 <span class="keywordtype">void</span> <a class="code" href="classVectorBits.html#ae8e4a406766c929a614359d5646c813" title="función que salva los datos en bytes">VectorBits :: Salvar</a> (ostream &amp; os)
<a name="l00224"></a>00224 {
<a name="l00225"></a>00225         os.write( (<span class="keywordtype">char</span>*)v, (nbits+7)/8 );
<a name="l00226"></a>00226 }
<a name="l00227"></a>00227 
<a name="l00228"></a>00228 <span class="keywordtype">void</span> <a class="code" href="classVectorBits.html#73d943f3f1e59bb32366c18c6da08e60" title="función que lee los datos en bytes">VectorBits :: Leer</a> (istream &amp; is, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> tam)
<a name="l00229"></a>00229 {
<a name="l00230"></a>00230         reservados=tam;
<a name="l00231"></a>00231         nbits= tam*8;
<a name="l00232"></a>00232         <span class="keyword">delete</span> [] v;
<a name="l00233"></a>00233         v = <span class="keyword">new</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> [tam];
<a name="l00234"></a>00234         is.read ((<span class="keywordtype">char</span>*)v, tam);
<a name="l00235"></a>00235 }
<a name="l00236"></a>00236 
<a name="l00237"></a><a class="code" href="classVectorBits.html#cab8f6781d2d22b3b633bba9b0dc80c4">00237</a> <span class="keywordtype">int</span> <a class="code" href="classVectorBits.html#cab8f6781d2d22b3b633bba9b0dc80c4" title="Funcion que calcula el numero entero de un vector de bits (binario).">VectorBits :: NumeroEntero</a> ()
<a name="l00238"></a>00238 {
<a name="l00239"></a>00239         <span class="keywordtype">int</span> nbyte = (nbits+7)/8;
<a name="l00240"></a>00240         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> val = 0;
<a name="l00241"></a>00241         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;nbyte; i++)
<a name="l00242"></a>00242                 val=val | (v[i]&lt;&lt;(8*i) );
<a name="l00243"></a>00243         <span class="keywordflow">return</span> val; 
<a name="l00244"></a>00244 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generado el Thu Jun 10 12:36:12 2010 para Metodología de la Programación II por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address>
</body>
</html>
